//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Data;
using CommunityServer.Components;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Discussions.Components;
using CommunityServer.Discussions.Controls;
using CA = ComponentArt.Web.UI;

namespace CommunityServer.ControlPanel.Moderation
{
	/// <summary>
	///		Summary description for ModerationForumListControl.
	/// </summary>
	public class ModerationForumListControl : BaseGridControl
	{
		protected CA.Grid Grid1;

		override protected void OnInit(EventArgs e)
		{
			this.Load += new EventHandler(this.Page_Load);
			base.OnInit(e);
		}

		private void Page_Load(object sender, EventArgs e)
		{
			buildGrid();
			Grid.DataBind();
		}

		protected override void buildGrid()
		{
		    ArrayList sections = Moderate.GetForumsToModerate();
			sections = Sections.FilterByAccessControl(sections, Permission.Moderate, CSContext.Current.User);

			ArrayList forumsToModerate = new ArrayList();
			foreach (Forum forum in sections)
				if (forum.PostsToModerate > 0)
					forumsToModerate.Add(forum);

		    DataTable forumTable = CADataConverter.ToDataTable(forumsToModerate, typeof(Forum));
			forumTable.DefaultView.Sort = "GroupName";
			Grid.DataSource = forumTable;
			this.RecordCount = forumTable.Rows.Count;

			ApplyUserSettings();
		}
	}
}
